<template>
  <div class="sign_list">
    <head-top head-title="选举报名" go-back="true"></head-top>
    <ul class="outer_ul">
      <li class="outer_li" v-if="singList && !flag" v-for="(a,index1) in singList" :key="index1">
        <ul class="inner_ul">
          <div class="outer_title">
            <span v-if="a[0].type ===1">业委会候选人报名</span>
            <span v-if="a[0].type ===2">筹备组报名</span>
            <span v-if="a[0].type ===3">换届工作组报名</span>
            <span v-if="a[0].type ===4">改选工作组报名</span>
            <span v-if="a[0].type ===5">监督委员会报名</span>
            <span v-if="a[0].type ===6">其他类型报名</span>
          </div>
          <li class="inner_li" v-for="(b,bindex) in a" :key="bindex">
            <h3>{{b.title}}</h3>
            <div class="tip_div">
              <p>创建时间：{{b.create_time*1000 | dateFmt('YYYY-MM-DD HH:mm:ss' )}}</p>
              <p>状态：
                <span v-if="b.isOver === '已结束'">{{b.isOver}}</span>
                <span v-if="b.isOver === '未开始'" class="green_color">{{b.isOver}}</span>
                <span v-if="b.isOver === '进行中'" class="blue_color">{{b.isOver}}</span>
              </p>
            </div>
            <div class="tip_btn">
              <button class="be_careful" @click="open(b.content)">注意事项</button>
              <button class="sign_up" @click="goLetter(b.isOver,a[0].type,b.id,b.title,b.status)">立即报名</button>
            </div>
          </li>
        </ul>
      </li>
      <!--注意事项内容弹窗-->
      <mt-popup
        v-model="popupVisible"
        class="care_popup" popup-transition="popup-fade">
        <div class="care_box">
          <div class="care_content">
            <span v-html="content"></span>
          </div>
          <div class="tip_close" @click="close()">
            <span>关闭</span>
          </div>
        </div>
      </mt-popup>
      <li class="default1" v-if="flag">
        <p>抱歉！暂无数据
        </p>
      </li>
    </ul>
  </div>
</template>

<script>
  import headTop from '../header/Header'
  import {singList} from '../../api/election'
  import {Toast} from 'mint-ui'

  export default {
    name: 'SignList',
    data() {
      return {
        singList: [],
        isFirstEnter: false,
        flag: false,
        popupVisible: false,
        content: ''
      }
    },
    created() {
      this.isFirstEnter = true
    },
    // 设置缓存从哪个页面返回
    beforeRouteEnter: (to, from, next) => {
      if (from.name === 'Letter') {
        to.meta.isBack = true
      }
      next()
    },
    activated() {
      if (!this.$route.meta.isBack || this.isFirstEnter) {
        this._singList()
      }
      this.$route.meta.isBack = false
      this.isFirstEnter = false
    },
    methods: {
      // 列表数据
      _singList() {
        this.flag = false
        singList().then(res => {
          console.log(res)
          if (res.code === 200) {
            this.singList = res.data
            // 数组里的type: 1:业委会报名  2：筹备组报名 3：换届报名  4：改选报名 5：监督委员会 6：其他报名
            // console.log(this.singList)
            // 判断暂无数据显示
            if (this.singList.length === 0) {
              this.flag = true
            }
          }
        })
      },
      goLetter(type, number, id, title, status) {
        console.log(status)
        if (type === '已结束') {
          Toast({
            message: '该项报名已经结束！',
            position: 'middle',
            duration: 3000
          })
          return
        }
        if (type === '未开始') {
          Toast({
            message: '该项报名还未开始！',
            position: 'middle',
            duration: 3000
          })
          return
        }
        if ((type === '进行中') && status === 0) {
          this.$router.push('/home/Letter/' + number + '/' + id + '/' + title)
        }
        if ((type === '进行中') && status === 1) {
          Toast({
            message: '您已经提交过报名了！',
            position: 'middle',
            duration: 3000
          })
          return
        }
      },
      open(content) {
        this.popupVisible = true
        this.content = content
        // console.log(content)
      },
      close() {
        this.popupVisible = false
      }
    },
    components: {
      headTop
    }
  }
</script>

<style lang="scss" scoped>
  .sign_list {
    padding-top: 40px;
    .outer_ul {
      .outer_li {
        .inner_ul {
          /*padding: 10px;*/
          .outer_title {
            background: #e6e6e6;
            font-size: 15px;
            color: #666666;
            padding: 10px;
          }
          .inner_li {
            border-bottom: 1px solid #d9d9d9;
            padding: 10px;
            h3 {
              font-size: 16px;
              color: #292929;
              font-weight: normal;
              width: 100%;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              padding-top: 10px;
            }
            .tip_div {
              display: -webkit-box;
              display: -moz-box;
              display: -webkit-flex;
              display: -moz-flex;
              display: -ms-flexbox;
              display: flex;
              align-items: center;
              justify-content: space-between;
              padding: 10px 0;
              p {
                font-size: 14px;
                color: #999999;
                .blue_color {
                  color: #2585d0;
                }
                .green_color {
                  color: #00c96c;
                }
              }
            }
            .tip_btn{
              width: 100%;
              display: inline-flex;
              justify-content: space-between;
              align-items: center;
              button{
                width: 48%;
                padding: 10px 0;
                border: none;
              }
              .be_careful{
                color: #292929;
              }
              .sign_up{
                background: #2585d0;
                color: #ffffff;
              }
            }
          }
          .inner_li:last-child {
            border-bottom: none;
          }
        }
      }
      .care_popup{
        width: 70%;
        border-radius: 10px;
        height: 300px;
        .care_box{
          background: #ffffff;
          position: relative;
          border-radius: 10px;
          .care_content{
            padding: 20px 10px;
            span{
              font-size: 15px;
              line-height: 25px;
              color: #333333;
            }
          }
          .tip_close{
            position: fixed;
            bottom: 0;
            width: 100%;
            padding: 10px 0;
            border-top: 1px solid #cccccc;
            text-align: center;
            span{
              letter-spacing: 8px;
              font-size: 15px;
              color: #0b7ad9;
            }
          }
        }
      }
      .default1 {
        width: 100%;
        flex: 1;
        display: inline-flex;
        padding-top: 0;
        justify-content: center;
        align-items: center;
        background: url("../../assets/default.png") no-repeat;
        background-size: 100px 100px;
        background-position: center;
        padding-bottom: 20px;
        p {
          font-size: 15px;
          color: #0b7ad9;
          margin-top: 190px;
        }
      }
    }
  }
</style>
